<?php
$SITEROOT = '../';
include_once($SITEROOT . 'assets/snippets/shoppingCart/dbconfig.inc.php');
include_once($SITEROOT . 'assets/snippets/shoppingCart/kiwee.class.php');

$kiwee = new Kiwee();

if(IN_MANAGER_MODE!="true") die('<b>' . $_lang['kiwee_include_order_error'] . '</b>');
if ($_SESSION['mgrPermissions']['settings'] != "1") { echo 'Insufficient permissions for this module.'; exit; }

$theme = $manager_theme ? "$manager_theme/":"";
$modx->manager->initPageViewState();
?>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/modal_window/javascripts/modal.js"></script>
<script type="text/javascript" src="actions/includes/interface.js"></script>
<link href="js/modal_window/stylesheets/modal.css" rel="stylesheet" type="text/css" />
<link href="actions/includes/kiwee.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
	function drl_add(){
		var poststr = "trxntype=drl_add&name=" + urival('name') + "&description=" + urival('description');
		makePOSTRequest('actions/ajax.php', poststr, 'drl_gridreload');
	}
	
	function drl_delete(id){
		if (confirm("Are you sure you want to delete this rate list?") == true) {
			makePOSTRequest('actions/ajax.php', "trxntype=drl_delete&listid=" + id, 'drl_gridreload');
		}
	}
	
	function drl_gridload(){
		makePOSTRequest('actions/ajax.php', "trxntype=drl_gridload", 'drl_gridload');
	}
	
	function drl_properties(id) {
		makePOSTRequest('actions/ajax.php', "trxntype=drl_properties&listid=" + id, 'drl_properties');
		showBox();
	}
	
	var listid;
	
	function drl_entries(id) {
		listid = id;
		makePOSTRequest('actions/ajax.php', "trxntype=drl_entries&listid=" + id, 'drl_entries');
		showBox();
	}
	
	function drl_entries_add(id){
		var poststr = "trxntype=drl_entries_add&listid=" + id + "&minqty=" + urival('drl_minqty') + "&discount=" + urival('drl_discrate');
		makePOSTRequest('actions/ajax.php', poststr, 'drl_entries');
	}
	
	function drl_entries_delete(id){
		var poststr = "trxntype=drl_entries_delete&listid=" + listid + "&id=" + id;
		makePOSTRequest('actions/ajax.php', poststr, 'drl_entries');
	}
	
	function drl_update(id){
		var poststr = "trxntype=drl_update&id=" + id + "&name=" + urival('listname') + "&desc=" + urival('listdesc');
		makePOSTRequest('actions/ajax.php', poststr, 'drl_gridload');
		hideBox();
	}
	
	function ajaxrendercomponent(name) {
        if (http_request.responseText.substring(0, 5) == "ERROR") {
            alert(http_request.responseText);
		} else if (name == 'drl_gridload') {
			document.getElementById('drl_grid').innerHTML=http_request.responseText;
		} else if (name == 'drl_gridreload') {
			drl_gridload();
		} else if (name == 'drl_properties') {
			document.getElementById('inner-box').innerHTML=http_request.responseText;
		} else if (name == 'drl_entries') {
			document.getElementById('inner-box').innerHTML=http_request.responseText;
		} else {
			alert("Unhandled response type " + name + ": " + http_request.responseText);
		}
	}
	drl_gridload();
</script>

<div id="overlay" onclick="hideBox()" style="display:none"></div>
<div id="box" style="display:none">
	<img id="close" src="js/modal_window/images/close.gif" onclick="hideBox()" alt="Close" title="Close this Window" />
	<div id="title" style="color: #ff9933; font-weight: bold; font-size: 14px;">Rate List Properties</div><br />
	<div id="inner-box"></div>
</div>

<div class="kiwee-msc" id="mascot"><a href="http://www.kiweecommerce.org"><img src="actions/includes/Kiwee-small.gif" /></a></div>
<div class="subTitle"><span class="right"></span></div>

<div class="sectionHeader"><?php echo $_lang["kiwee_discount_header"]; ?></div>
<div class="sectionBody">
	<p><?php echo $_lang['kiwee_discount_desc']; ?></p>
<div>
<br />
	<form method="POST" action="">
		<label>Name:&nbsp;</label><input id="name" name="name" type="text" length=20 />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<label>Description:&nbsp;</label><input id="description" name="description" type="text" length=100 />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<button onclick="drl_add();"><?php echo $_lang['kiwee_discount_add']; ?></button>
		<br /><br />
  	</form>
	<div id="drl_grid" name="drl_grid" ></div>
</div>
